<template>
  <div class="header-wrapper d-flex flex-jc-sb flex-ai-c">
    <div class="w-content p-re d-flex flex-jc-sb fs-18">
      <div class="header-left h-100 d-flex">
        <div class="header-logo d-flex h-100 flex-start flex-ai-c" @click="goToSys(0)"><img :src="logoImg"></div>
        <div class="header-category d-flex h-100 flex-start flex-ai-c">
          <div
            v-for="(item, index) in menuList"
            :key="index"
            class="header-category-item d-flex flex-ai-c"
            :class="{ 'active': currentIndex === index }"
            @click="goToSys(index)"
          >{{ item.name }}
          </div>
        </div>
      </div>
      <div class="header-right d-flex flex-jc-sa flex-ai-c h-100">
        <!--        <div class="header-search d-flex flex-jc-c flex-ai-c" @click="chnageSearch"><img :src="searchImg"></div>-->
        <div class="header-login d-flex flex-ai-c fs-16" @click="sysLogin">登录</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import portalUtil from '@/utils/portal-util'

export default {
  name: 'PortalHeader',
  props: {
    currentIndex: {
      type: Number,
      default: 0
    },
    register: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      searchShow: false,
      preloader: true, // 展示预加载
      loaded: false,
      sticky: true, // 头部固定
      currentDate: null,
      menuList: [],
      loginFlag: false,
      searchForm: {
        keyword: null
      },
      searchSelectedImg: require('@/assets/portal_images/search_s.png'),
      searchImg: require('@/assets/portal_images/search_s.png'),
      logoImg: require('@/assets/portal_images/logo.png'),
      closeImg: require('@/assets/portal_images/close.png'),
      hotImg: require('@/assets/portal_images/hot.png')
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  created() {
    const that = this
    that.menuList = portalUtil.protalTabPages
    this.searchShow = false
    this.searchForm.keyword = null
  },
  methods: {
    search(content) {
      if (content !== null) {
        this.searchForm.keyword = content
      }
      if (this.searchForm.keyword === null || this.searchForm.keyword === '') {
        this.$message({
          message: '请输入关键字',
          type: 'warning'
        })
        return
      }
      this.$router.push({ path: '/search', query: { keyword: this.searchForm.keyword }})
    },
    chnageSearch() {
      this.searchShow = !this.searchShow
    },
    sysLogin() {
      this.$router.push({ path: '/login', query: null })
    },
    goToSys(index) {
      portalUtil.gotoPageIndex(this, index, {})
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/styles/variables.scss';

.header-wrapper {
  height: 72px;
  width: 100%;

  .search-warp {
    position: absolute;
    width: 450px;
    height: 168px;
    border-left: 1px solid #C9D3E0;
    border-right: 1px solid #C9D3E0;
    z-index: 99;
    top: 0;
    left: 590px;
    background-color: $portalWhiteColor;

    .search-input-section {
      height: 72px;

      input {
        width: 300px;
        height: 32px;
        border: transparent;
        border-radius: 4px;
        padding-left: 10px;
      }

      .icon-item {
        border-right: 1px solid #C9D3E0;
        height: 20px;
        width: 70px;
        text-align: center;
        cursor: pointer;

        img {
          width: 17px;
          height: 17px;
        }
      }
    }

    .search-hot-section {
      height: 96px;
      border: 1px solid #C9D3E0;
      line-height: 48px;
      padding-left: 24px;

      .hot-item {
        cursor: pointer;
        margin-right: 40px;
      }

      img {
        margin-left: 8px;
        width: 38px;
        height: 16px;
      }
    }
  }

  .header-left {
    .header-logo {
      margin-right: 56px;
      cursor: pointer;
    }

    .header-category {
      .header-category-item {
        margin-right: 48px;
        cursor: pointer;
        position: relative;
        height: 26px;
      }

      .header-category-item:hover:before {
        content: "";
        height: 2px;
        overflow: hidden;
        display: block;
        left: 0;
        bottom: -6px;
        position: absolute;
        width: 100%;
        background: $portalBlueColor;
        transform-origin: left;
        animation: scaleX 6s linear infinite;
      }

      .active:before {
        content: "";
        height: 2px;
        overflow: hidden;
        display: block;
        left: 0;
        bottom: -6px;
        position: absolute;
        width: 100%;
        background: $portalBlueColor;
        transform-origin: left;
        animation: scaleX 6s linear infinite;
      }
    }
  }

  .header-right {
    width: 150px;

    .header-search {
      border-left: 1px solid #C9D3E0;
      border-right: 1px solid #C9D3E0;
      height: 20px;
      width: 70px;
      text-align: center;
      cursor: pointer;

      img {
        width: 17px;
        height: 17px;
      }
    }

    .header-login {
      height: 25px;
      cursor: pointer;
      background-color: #0279FF;
      color: #ffffff;
      border-radius: 5px;
      padding: 5px 10px;
    }

    .header-register {
      height: 25px;
      cursor: pointer;
      background-color: #0279FF;
      color: #ffffff;
      border-radius: 5px;
      padding: 5px 10px;
    }
  }

}
</style>

